<!DOCTYPE>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <title>用户添加</title>
    <link href="/css/style2.css" rel="stylesheet" type="text/css"/>
    <link href="/css/select.css" rel="stylesheet" type="text/css"/>
    <script src="/js/jquery.js" type="text/javascript"></script>
    <script src="/js/jquery.idTabs.min.js" type="text/javascript"></script>
    <script src="/js/select-ui.min.js" type="text/javascript"></script>
    <script src="/js/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        KE.show({
            id: 'content7',
            cssPath: './index.css'
        });
    </script>

    <script type="text/javascript">
        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });
            $(".select2").uedSelect({
                width: 167
            });
            $(".select3").uedSelect({
                width: 100
            });
        });
    </script>
    <script language="javascript">

    </script>


</head>

<body>
<form action="save" id="form">
    <input name="id" th:value="${user.id}" type="hidden">
    <div class="place">
        <span>位置：</span>
        <ul class="placeul">
            <li><a href="/user/userSearch">用户管理</a></li>
            <li><a href="#">修改用户</a></li>
        </ul>
    </div>

    <div class="formbody">

        <div class="formtitle"><span>基本信息</span></div>

        <ul class="forminfo">
            <li>
                <label>工号 <font color="red">*</font></label>
                </label><input class="scinput" name="account" readonly="readonly" th:value="${user.account}"
                               type="text"/></li>
            <li>
                <label>密码 <font color="red">*</font></label>
                <input class="dfinput" name="password" th:value="${user.password}" type="password"/>
            </li>
            <li>
                <label>确认密码 <font color="red">*</font></label><input class="dfinput" name="password1"
                                                                     th:value="${user.password}"
                                                                     type="password"/>
            </li>
            <li>
                <label>姓名 <font color="red">*</font></label>
                </label><input class="dfinput" name="name" th:value="${user.name}" type="text"/>
            </li>
            <li><label>部门</label>
                <div class="vocation">
                    <select class="select3" name="departmentId">
                        <option>--请选择--</option>
                        <option th:each="p:${dept}" th:selected="${p.departmentName==user.departmentId}"
                                th:text="${p.departmentName}"
                                th:value="${p.departmentName}">研发二部
                        </option>
                    </select>
                </div>
            </li>
            <li>
                <label>性别</label>
                <cite><input name="sex" th:checked="${user.sex==0}" th:value="0" type="radio"/>
                    男&nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="sex" th:checked="${user.sex==1}" th:value="1" type="radio"/>
                    女</cite></li>
            <li><label>手机号码 <font color="red">*</font></label><input class="dfinput" name="mobile"
                                                                     th:value="${user.mobile}"
                                                                     type="text"/></li>
            <li><label>出生日期</label>
                <input class="dfinput" name="birthday"
                       onClick="WdatePicker({startDate:'',dateFmt:'yyyy-MM-dd'})" th:value="${user.birthday}"
                       type="text"/></li>
            <li><label>邮箱 <font color="red">*</font></label><input class="dfinput" name="email" th:value="${user.email}"
                                                                   type="text"/></li>


            <li><label>权限 <font color="red">*</font></label>
                <div class="vocation">
                    <select class="select3" name="userType">
                        <option th:selected="${user.userType==0}" value="0">超级管理员</option>
                        <option th:selected="${user.userType==1}" value="1">部门主管</option>
                        <option th:selected="${user.userType==2}" value="2">普通员工</option>
                    </select>
                </div>
            </li>


            <li><label>&nbsp;</label><input class="btn" name="" onclick="saveButton()" type="button" value="确认保存"/></li>
        </ul>
    </div>
</form>
</body>
<script>
    function saveButton() {
        let form = $("#form").serializeArray()
        form.shift()
        console.log(form);
        if (form[0].value == '' || form[1].value == '' || form[2].value == '' || form[3].value == '') {
            alert('请输入必填项')
            return
        } else if (form[1].value != form[2].value) {
            alert("两次密码不一样，请重新输入！")
            return
        } else if (form[6].value.length != 11) {
            alert('手机号码格式不正确！')
            return
        } else if (form[7].value.indexOf('-') == -1) {
            alert('时间分割请以“-”！')
            return
        } else if (!form[8].value.match(
            '^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$')) {
            alert('邮箱格式不正确！')
            return
        }
        $("#form").submit()
    }
</script>
</html>
